1f52af6aa0d64e87eb87ece2664160328188257b,deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkProcessor.java,DeepLinkProcessor,generateDeepLinkDelegate,#,273

Before Change


        .addStatement("parameterMap.put(queryParameter, queryParameterValue)")
        .endControlFlow()
        .endControlFlow()
        .addStatement("parameterMap.put(DeepLink.URI, uri.toString())")
        .beginControlFlow("try")
        .addStatement("Class<?> c = entry.getActivityClass()")
        .addStatement("$T newIntent", ANDROID_INTENT)
        .beginControlFlow("if (entry.getType() == DeepLinkEntry.Type.CLASS)")
        .addStatement("newIntent = new Intent(activity, c)")
        .nextControlFlow("else")
        .addStatement("$T method = c.getMethod(entry.getMethod(), $T.class)", Method.class,
            ClassName.get("android.content", "Context"))
        .addStatement("newIntent = (Intent) method.invoke(c, activity)")
        .endControlFlow()
        .beginControlFlow("if (newIntent.getAction() == null)")
        .addStatement("newIntent.setAction(sourceIntent.getAction())")
        .endControlFlow()
        .beginControlFlow("if (newIntent.getData() == null)")
        .addStatement("newIntent.setData(sourceIntent.getData())")
        .endControlFlow()
        .addStatement("$T parameters", ClassName.get("android.os", "Bundle"))
        .beginControlFlow("if (sourceIntent.getExtras() != null)")
        .addStatement("parameters = new Bundle(sourceIntent.getExtras())")
        .nextControlFlow("else")
        .addStatement("parameters = new Bundle()")
        .endControlFlow()
        .beginControlFlow(
            "for (Map.Entry<String, String> parameterEntry : parameterMap.entrySet())")
        .addStatement("parameters.putString(parameterEntry.getKey(), parameterEntry.getValue())")
        .endControlFlow()
        .addStatement("newIntent.putExtras(parameters)")
        .addStatement("newIntent.putExtra(DeepLink.IS_DEEP_LINK, true)")
        .beginControlFlow("if (activity.getCallingActivity() != null)")
        .addStatement("newIntent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT)")
        .endControlFlow()
        .addStatement("activity.startActivity(newIntent)")
        .addStatement("return createResultAndNotify(activity, true, uri, null)")
        .nextControlFlow("catch (NoSuchMethodException exception)")
        .addStatement(
            "return createResultAndNotify(activity, false, uri, \"Deep link to "
                + "non-existent method: \" + entry.getMethod())")
        .nextControlFlow("catch (IllegalAccessException exception)")
        .addStatement(
            "return createResultAndNotify(activity, false, uri, \"Could not deep "
                + "link to method: \" + entry.getMethod())")
        .nextControlFlow("catch ($T  exception)", InvocationTargetException.class)
        .addStatement(
            "return createResultAndNotify(activity, false, uri, \"Could not deep "
                + "link to method: \" + entry.getMethod())")
        .endControlFlow()
        .nextControlFlow("else")
        .addStatement("return createResultAndNotify(activity, false, uri, "
            + "\"No registered entity to handle deep link: \" + uri.toString())")
        .endControlFlow()
        .build();

    TypeSpec deepLinkDelegate = TypeSpec.classBuilder("DeepLinkDelegate")
        .addModifiers(Modifier.PUBLIC, Modifier.FINAL)

After Change


        .addStatement("parameterMap.put(queryParameter, queryParameterValue)")
        .endControlFlow()
        .endControlFlow()
        .addStatement("parameterMap.put(DeepLink.URI, uri.toString())")
        .addStatement("$T parameters", ClassName.get("android.os", "Bundle"))
        .beginControlFlow("if (sourceIntent.getExtras() != null)")
        .addStatement("parameters = new Bundle(sourceIntent.getExtras())")
        .nextControlFlow("else")
        .addStatement("parameters = new Bundle()")
        .endControlFlow()
        .beginControlFlow(
                "for (Map.Entry<String, String> parameterEntry : parameterMap.entrySet())")
        .addStatement("parameters.putString(parameterEntry.getKey(), parameterEntry.getValue())")
        .endControlFlow()
        .beginControlFlow("try")
        .addStatement("Class<?> c = entry.getActivityClass()")
        .addStatement("$T newIntent", ANDROID_INTENT)
        .beginControlFlow("if (entry.getType() == DeepLinkEntry.Type.CLASS)")
        .addStatement("newIntent = new Intent(activity, c)")
        .nextControlFlow("else")
        .addStatement("$T method", Method.class)
        .beginControlFlow("try")
        .addStatement("method = c.getMethod(entry.getMethod(), $T.class)",
                ClassName.get("android.content", "Context"))
        .addStatement("newIntent = (Intent) method.invoke(c, activity)")
        .nextControlFlow("catch ($T exception)", NoSuchMethodException.class)
        .addStatement("method = c.getMethod(entry.getMethod(), $T.class, $T.class)",
            ClassName.get("android.content", "Context"), ClassName.get("android.os", "Bundle"))
        .addStatement("newIntent = (Intent) method.invoke(c, activity, parameters)")
        .endControlFlow()
        .endControlFlow()
        .beginControlFlow("if (newIntent.getAction() == null)")
        .addStatement("newIntent.setAction(sourceIntent.getAction())")
        .endControlFlow()
        .beginControlFlow("if (newIntent.getData() == null)")
        .addStatement("newIntent.setData(sourceIntent.getData())")
        .endControlFlow()
        .addStatement("newIntent.putExtras(parameters)")
        .addStatement("newIntent.putExtra(DeepLink.IS_DEEP_LINK, true)")
        .beginControlFlow("if (activity.getCallingActivity() != null)")
        .addStatement("newIntent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT)")
        .endControlFlow()
        .addStatement("activity.startActivity(newIntent)")
        .addStatement("return createResultAndNotify(activity, true, uri, null)")
        .nextControlFlow("catch (NoSuchMethodException exception)")
        .addStatement(
            "return createResultAndNotify(activity, false, uri, \"Deep link to "
                + "non-existent method: \" + entry.getMethod())")
        .nextControlFlow("catch (IllegalAccessException exception)")
        .addStatement(
            "return createResultAndNotify(activity, false, uri, \"Could not deep "
                + "link to method: \" + entry.getMethod())")
        .nextControlFlow("catch ($T  exception)", InvocationTargetException.class)
        .addStatement(
            "return createResultAndNotify(activity, false, uri, \"Could not deep "
                + "link to method: \" + entry.getMethod())")
        .endControlFlow()
        .nextControlFlow("else")
        .addStatement("return createResultAndNotify(activity, false, uri, "
            + "\"No registered entity to handle deep link: \" + uri.toString())")
        .endControlFlow()
        .build();

    TypeSpec deepLinkDelegate = TypeSpec.classBuilder("DeepLinkDelegate")